package models;

import java.util.Date;

import org.apache.ibatis.session.SqlSession;

import com.aton.db.SessionFactory;

import models.mappers.OplogMapper;
import utils.UUIDString;

public class Oplog {
	public String id;
	public String model;
	public Date optime;
	public String operatorid;
	public String opname;
	public String menuname;
	public Oplog(){
		
	}
	public Oplog(String id, String model, Date optime,String operatorid, String opname,String menuname) {
		super();
		this.id = id;
		this.model = model;
		this.optime = optime;
		this.operatorid=operatorid;
		this.opname = opname;
		this.menuname=menuname;
	}
	
	public Oplog(String operatorid,String model,String menuname) {
		super();
		this.model = model;
		this.operatorid = operatorid;
		this.menuname=menuname;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getModel() {
		return model;
	}
	public void setModel(String model) {
		this.model = model;
	}
	public Date getOptime() {
		return optime;
	}
	public void setOptime(Date optime) {
		this.optime = optime;
	}
	public String getOpname() {
		return opname;
	}
	public void setOpname(String opname) {
		this.opname = opname;
	}
	
	public String getOperatorid() {
		return operatorid;
	}
	public void setOperatorid(String operatorid) {
		this.operatorid = operatorid;
	}
	
	public String getMenuname() {
		return menuname;
	}
	public void setMenuname(String menuname) {
		this.menuname = menuname;
	}
	/**
	 * 保存操作日志
	 *
	 * @Title: save 
	 * @param model
	 * @return: void
	 */
	public void save(Oplog oplog){
		oplog.id=UUIDString.create();
		oplog.optime=new Date();
		SqlSession ss = SessionFactory.getSqlSessionWithoutAutoCommit();
		try{
			OplogMapper mapper=ss.getMapper(OplogMapper.class);
			mapper.save(oplog);
			ss.commit();
		}catch(Exception e){
			e.printStackTrace();
		}
		finally{
			ss.close();
		}
	}
}
